<!-- daterange picker -->
<link rel="stylesheet" href="__PUBLIC__/AdminLTE/plugins/daterangepicker/daterangepicker.css">
<style>
    .button-margin{
        display: block;
        right: auto;
    }
</style>
<div class="content-wrapper">
    <section class="content-header">
        <h1>下单</h1>
        <ol class="breadcrumb">
            <li><a href="/admin"><i class="fa fa-dashboard"></i> 首页</a></li>
            <li class="active">客户管理</li>
            <li class="active">客户列表</li>
            <li class="active">下单</li>
        </ol>
    </section>
    <section class="content">
        <div class="row">
            <div class="container-fluid">
                <div class="col-md-3">
                    <div class="box box-widget widget-user-2">
                        <!-- Add the bg color to the header using any of the bg-* classes -->
                        <if condition="$customer.gender eq 1 ">
                                <div class="widget-user-header bg-aqua-active">
                                    <div class="widget-user-image">
                                        <img class="img-circle" src="__PUBLIC__/AdminLTE/dist/img/avatar5.png" alt="User Avatar">
                                    </div>
                                    <!-- /.widget-user-image -->
                                    <h3 class="widget-user-username">{$customer.name} <span class="pull-right badge bg-red-gradient">{$customer.gender_desc}</span></h3>
                                    <h5 class="widget-user-desc">{$customer.company_name}</h5>
                                </div>
                            <else />
                                <div class="widget-user-header bg-purple-active">
                                    <div class="widget-user-image">
                                        <img class="img-circle" src="__PUBLIC__/AdminLTE/dist/img/avatar2.png" alt="User Avatar">
                                    </div>
                                    <!-- /.widget-user-image -->
                                    <h3 class="widget-user-username">{$customer.name} <span class="pull-right badge bg-red-gradient">{$customer.gender_desc}</span></h3>
                                    <h5 class="widget-user-desc">{$customer.company_name}</h5>
                                </div>
                        </if>

                        <div class="box-footer no-padding">
                            <ul class="nav nav-stacked">
                                <li><a href="#">客户级别 <span class="pull-right badge bg-blue">{$customer.level_desc}</span></a></li>
                                <li><a href="#">客户类别 <span class="pull-right badge bg-aqua">{$customer.type_desc}</span></a></li>
                                <li><a href="#">推广产品&游戏 <span class="pull-right badge bg-green">{$customer.product_name}</span></a></li>
                                <li><a href="#">手机号 <span class="pull-right badge bg-purple">{$customer.mobile}</span></a></li>
                                <li><a href="#">固话 <span class="pull-right badge bg-info">{$customer.tel}</span></a></li>
                                <li><a href="#">微信 <span class="pull-right badge bg-green-active">{$customer.wechat}</span></a></li>
                                <li><a href="#">QQ <span class="pull-right badge bg-red">{$customer.qq}</span></a></li>
                                <li><a href="#">产品一级名称 <span class="pull-right badge bg-blue-active">{$customer.first_name}</span></a></li>
                            </ul>
                        </div>
                    </div>
                </div>
                <div class="col-md-9">
                    <!-- 添加产品 -->
                    <div class="box box-info">
                        <div class="box-header with-border">
                            添加产品
                        </div>
                        <div class="box-body">
                            <form action="javascript:;" class="form-horizontal" method="POST">
                                <input type="hidden" id="p_id" name="p_id" value="{$customer.cid}"/>
                                <input type="hidden" id="s_id" name="s_id" value="{$customer.second_cid}"/>
                                <input type="hidden" id="order_id" name="order_id" value="{$orderInfo.order_id}"/>
                                <div class="form-group">
                                    <label for="t_id" class="col-sm-3 control-label"> 选择三级分类 </label>
                                    <div class="col-sm-6">
                                        <select class="form-control" id="t_id" name="t_id">
                                            <option value="0">请选择</option>
                                            <foreach name="three_cate" item="p">
                                                <option value="{$p.id}">{$p.name}</option>
                                            </foreach>
                                        </select>
                                    </div>
                                </div>
                                <div class="form-group">
                                    <label for="item_id" class="col-sm-3 control-label"> 选择产品 </label>
                                    <div class="col-sm-6">
                                        <select class="form-control" id="item_id" name="item_id">
                                            <option value="0">请选择</option>
                                        </select>
                                    </div>
                                </div>
                                <div class="form-group">
                                    <label for="form-field-1" class="col-sm-4 control-label"></label>
                                    <div class="col-sm-6">
                                        <button type="button" class="btn btn-info btn-sm save-btn">添加</button>
                                        &nbsp;
                                        <button type="reset" class="btn btn-sm">重置</button>
                                    </div>
                                </div>
                            </form>
                        </div>
                    </div>

                    <!-- 产品详细 -->
                    <div class="box box-primary">
                        <div class="box-header with-border">
                            已添加产品
                        </div>
                        <div class="box-body">
                            <table class="table table-bordered">
                                <thead>
                                <th style="width: 10px">#</th>
                                <th>项目</th>
                                </thead>
                                <tbody id="itemList">
                                <if condition="count($itemList) eq 0 "><tr><td colspan="2">暂未添加</td></tr></if>
                                <foreach name="itemList" item="item" key="key">
                                    <tr>
                                        <td>{$key+1}</td>
                                        <td>{$item.first_name}-{$item.second_name}-{$item.item_name}</td>
                                    </tr>
                                </foreach>

                                </tbody>
                            </table>
                        </div>
                    </div>

                    <if condition="$customer.phase egt 10">
                        <!-- 产品编辑 -->
                            <div class="box box-primary">
                                <div class="box-header with-border">
                                </div>
                                <div class="box-body">
                                <div class="nav-tabs-custom">
                                    <ul class="nav nav-tabs">
                                        <foreach name="itemList" item="p_item" key="k">
                                            <li class='<if condition="$k eq 0">active</if>'><a href="#activity_{$p_item.id}" data-toggle="tab" aria-expanded="true">{$p_item.second_name}-{$p_item.item_name}</a></li>
                                        </foreach>
                                    </ul>
                                    <div class="tab-content">
                                        <foreach name="itemList" item="s_item" key="sk">
                                            <div class='tab-pane <if condition="$sk eq 0">active</if>' id="activity_{$s_item.id}">
                                            <form class="form-horizontal">
                                                <input type="hidden" id="oi_id_{$s_item.id}" value="{$s_item.id}">
                                                <input type="hidden" id="oi_item_id_{$s_item.id}" value="{$s_item.item_id}">
                                                <input type="hidden" id="oi_eid_{$s_item.id}" value="{$s_item.tpl.id}">
                                                <div class="form-group">
                                                    <label for="oi_quoted_type_{$s_item.id}" class="col-sm-2 control-label">询价</label>

                                                    <div class="col-sm-10">
                                                        <select type="text" class="form-control" id="oi_quoted_type_{$s_item.id}">
                                                            <option value="1" <if condition="$s_item.quoted_type eq 1">selected</if>>预估报价</option>
                                                            <option value="2" <if condition="$s_item.quoted_type eq 2">selected</if>>百度询价</option>
                                                            <option value="3" <if condition="$s_item.quoted_type eq 3">selected</if>>不询价</option>
                                                        </select>
                                                    </div>
                                                </div>
                                                <div class="form-group">
                                                    <label for="oi_advertiser_{$s_item.id}" class="col-sm-2 control-label">广告主</label>

                                                    <div class="col-sm-10">
                                                        <input type="text" class="form-control" id="oi_advertiser_{$s_item.id}" placeholder="广告主" value="{$s_item.advertiser}">
                                                    </div>
                                                </div>
                                                <div class="form-group">
                                                    <label for="oi_promote_product_{$s_item.id}" class="col-sm-2 control-label">推广产品</label>

                                                    <div class="col-sm-10">
                                                        <input type="text" class="form-control" id="oi_promote_product_{$s_item.id}" placeholder="推广产品" value="{$s_item.promote_product}">
                                                    </div>
                                                </div>
                                                <div class="form-group">
                                                    <label for="oi_trade_{$s_item.id}" class="col-sm-2 control-label">所属行业</label>

                                                    <div class="col-sm-10">
                                                        <input type="text" class="form-control" id="oi_trade_{$s_item.id}" placeholder="所属行业" value="{$typeList[$customer['type']]}" disabled readonly>
                                                    </div>
                                                </div>
                                                <div class="form-group">
                                                    <label for="oi_put_time_{$s_item.id}" class="col-sm-2 control-label">投放时间</label>
                                                    <div class="input-group col-sm-10">
                                                        <div class="input-group-addon">
                                                            <i class="fa fa-calendar"></i>
                                                        </div>
                                                        <input type="text" class="form-control put-time-d" name="search_time" id="oi_put_time_{$s_item.id}" value="{$s_item.put_time}">
                                                    </div>
                                                    <!-- /.input group -->
                                                </div>
                                                <div class="form-group">
                                                    <label for="oi_port_{$s_item.id}" class="col-sm-2 control-label">投放端口</label>
                                                    <div class="col-sm-10">
                                                        <input id="oi_port_{$s_item.id}" type="hidden" name="put_port" value="{$s_item.port}"/>
                                                        <div id="put_port_copy">
                                                            <php>$port_data = $s_item['item_put_port'];</php>
                                                            <foreach name="port_data" item="port">
                                                                <label class="col-sm-pull-1">
                                                                    <input type="checkbox" name="put_port" data-id="{$s_item.id}" class="minimal-red" value="{$port}" <php>if(in_array($port, explode(',',$s_item["port"]))):echo 'checked'; endif;</php>>
                                                                    {$port}
                                                                </label>
                                                            </foreach>
                                                        </div>
                                                    </div>
                                                </div>
                                                <div class="form-group">
                                                    <label for="oi_place_{$s_item.id}" class="col-sm-2 control-label">投放位置</label>
                                                    <div class="col-sm-10">
                                                        <input id="oi_place_{$s_item.id}" type="hidden" name="put_place" value="{$s_item.place}"/>
                                                        <div id="put_place_copy">
                                                            <php>$place_data = $s_item['item_put_place'];</php>
                                                            <foreach name="place_data" item="place">
                                                                <label class="col-sm-pull-1">
                                                                    <input type="checkbox" name="put_place" class="minimal-red" data-id="{$s_item.id}" value="{$place}" <php>if(in_array($place, explode(',',$s_item["place"]))):echo 'checked'; endif;</php>>
                                                                    {$place}
                                                                </label>
                                                            </foreach>
                                                        </div>
                                                    </div>
                                                </div>
                                                <div class="form-group">
                                                    <label for="oi_post_bar_{$s_item.id}" class="col-sm-2 control-label">投放贴吧</label>

                                                    <div class="col-sm-10">
                                                        <input type="text" class="form-control oi_post_bar" id="oi_post_bar_{$s_item.id}" placeholder="投放贴吧" value="{$s_item.post_bar}" data-role="tagsinput">
                                                        <label class="error"><b style="color: red;">注：</b>吧之间用英文逗号隔开或者直接Enter键</label>
                                                    </div>
                                                </div>
                                                <!-- 保存 -->
                                                <if condition="$s_item['s_data']">
                                                        <php>$all_data = json_decode($s_item['s_data'],true);</php>
                                                        <foreach name="all_data" item="detail">
                                                            <if condition="$detail.type eq 'input'">
                                                                <div class="form-group">
                                                                    <input type="hidden" class="a_data_{$s_item.id}" data-title="{$detail.title}" data-type="{$detail.type}" data-values="{$detail.values}"/>
                                                                    <label class="col-sm-2 control-label">{$detail.title}</label>
                                                                    <div class="col-sm-10">
                                                                        <input class="form-control a_data_v_{$s_item.id}" value="{$detail.val}" placeholder="{$detail.title}"/>
                                                                    </div>
                                                                </div>
                                                            <else />
                                                                <div class="form-group">
                                                                    <input type="hidden" class="a_data_{$s_item.id}" data-item="{$s_item.id}" data-title="{$detail.title}" data-type="{$detail.type}" data-values="{$detail.values}"/>
                                                                    <label class="col-sm-2 control-label">{$detail.title}</label>
                                                                    <div class="col-sm-10">
                                                                        <php> $arr = explode(',',$detail['values']);</php>
                                                                        <select class="form-control a_data_v_{$s_item.id}">
                                                                            <foreach name="arr" item="val">
                                                                                <option value="{$val}" <if condition="$detail.val eq $val">selected</if>>{$val}</option>
                                                                            </foreach>
                                                                        </select>
                                                                    </div>
                                                                </div>
                                                            </if>
                                                        </foreach>
                                                    <else />
                                                    <!--模板-->
                                                    <if condition="count($s_item.tpl.tpl_detail) gt 0 ">
                                                        <foreach name="s_item.tpl.tpl_detail" item="detail">
                                                            <if condition="$detail.type eq 'input'">
                                                                <div class="form-group">
                                                                    <input type="hidden" class="a_data_{$s_item.id}" data-item="{$s_item.id}" data-title="{$detail.title}" data-type="{$detail.type}" data-values="{$detail.data}"/>
                                                                    <label class="col-sm-2 control-label">{$detail.title}</label>
                                                                    <div class="col-sm-10">
                                                                        <input class="form-control a_data_v_{$s_item.id}" value="" placeholder="{$detail.title}"/>
                                                                    </div>
                                                                </div>
                                                                <else />
                                                                <div class="form-group">
                                                                    <input type="hidden" class="a_data_{$s_item.id}" data-item="{$s_item.id}" data-title="{$detail.title}" data-type="{$detail.type}" data-values="{$detail.data}"/>
                                                                    <label class="col-sm-2 control-label">{$detail.title}</label>
                                                                    <div class="col-sm-10">
                                                                        <php> $arr = explode(',',$detail['data']);</php>
                                                                        <select class="form-control a_data_v_{$s_item.id}">
                                                                            <foreach name="arr" item="val">
                                                                                <option value="{$val}">{$val}</option>
                                                                            </foreach>
                                                                        </select>
                                                                    </div>
                                                                </div>
                                                            </if>
                                                        </foreach>
                                                    </if>

                                                </if>
                                                <div class="form-group">
                                                    <div class="col-sm-offset-2 col-sm-10">
                                                        <button type="button" class="btn btn-danger btn-save-info" data-id="{$s_item.id}">保存</button>
                                                    </div>
                                                </div>
                                            </form>
                                        </div>
                                        </foreach>
                                        <!-- /.tab-pane -->
                                    </div>
                                    <!-- /.tab-content -->
                                </div>
                                <!-- 报价 排期 -->
                                <div class="box box-primary">
                                    <div class="box-header with-border">
                                        产品列表
                                    </div>
                                    <div class="box-body">
                                        <table class="table table-bordered">
                                            <thead>
                                            <tr>
                                                <th>产品名称</th>
                                                <th>报价类型</th>
                                                <th>广告主</th>
                                                <th>推广产品</th>
                                                <th>所属行业</th>
                                                <th>投放端&位置</th>
                                                <th>投放广告位</th>
                                                <th>投放吧</th>
                                                <th>投放时间</th>
                                                <th>报价</th>
                                                <th>确认排期</th>
                                                <th>报价详情</th>
                                                <th>操作</th>
                                            </tr>
                                            </thead>
                                            <tbody id="itemList-b">
                                                <if condition="count($itemList) eq 0 "><tr><td colspan="11">暂未添加</td></tr></if>
                                                <foreach name="itemList" item="item" key="key">
                                                    <tr>
                                                        <td>{$item.first_name}-{$item.second_name}-{$item.item_name}</td>
                                                        <td>
                                                            <if condition="$item.quoted_type eq 1 ">
                                                                <span class="label label-success">预估报价</span>
                                                                <elseif condition="$item.quoted_type eq 2" />
                                                                <span class="label label-info">百度询价</span>
                                                                <else />
                                                                <span class="label label-default">不询价</span>
                                                            </if>

                                                        </td>
                                                        <td>{$item.advertiser}</td>
                                                        <td>{$item.promote_product}</td>
                                                        <td>{$item.trade}</td>
                                                        <td>{$item.port}</td>
                                                        <td>{$item.place}</td>
                                                        <td>{$item.post_bar}</td>
                                                        <td>{$item.put_time}</td>
                                                        <td>{$item.total_price}</td>
                                                        <td>{$item.phase}</td>
                                                        <td>
                                                            <if condition="$item.quoted_file neq ''">
                                                                <a type="button" class="btn btn-sm btn-primary" href="/admin/index/downloadFile?file={$item.quoted_file|urlencode}"><i class="fa fa-cloud-download"></i>详情</a>
                                                                <else />
                                                                <label class="label label-default">暂未上传</label>
                                                            </if>
                                                        </td>
                                                        <td>
                                                            <button type="button" class="btn btn-xs btn-danger btn-delete" data-id="{$item.id}">放弃</button>
                                                        </td>
                                                    </tr>
                                                </foreach>
                                            </tbody>
                                            <tfoot>
                                            <tr>
                                                <th colspan="13">
                                                    备注：
                                                    <if condition="$orderInfo.refuse_quote_reason neq ''">
                                                        <p>驳回报价：{$orderInfo.refuse_quote_reason}</p>
                                                    </if>
                                                    <if condition="$orderInfo.refuse_phase_reason neq ''">
                                                        <p>驳回排期：{$orderInfo.refuse_phase_reason}</p>
                                                    </if>
                                                </th>
                                            </tr>
                                            </tfoot>
                                        </table>
                                    </div>
                                    <div class="box-footer">
                                        <if condition="($orderInfo.status neq -5) OR ($orderInfo.status neq -1)">
                                            <?php if($orderInfo['status'] == -10): ?>
                                                <button class="btn btn-success btn-sm btn-quoted" data-status="{$orderInfo.status}" data-id="{$orderInfo.id}">重新申请报价</button>
                                                <?php else: ?>
                                                <?php if(($sCate['is_enquiry']==1) && ($orderInfo['status']==5)): ?>
                                                    <button class="btn btn-success btn-sm btn-quoted" data-status="{$orderInfo.status}" data-id="{$orderInfo.id}">申请报价</button>
                                                <?php endif;?>
                                            <?php endif; ?>
                                            <?php if($orderInfo['status'] == -15): ?>
                                            <button class="btn btn-success btn-sm btn-phase" data-status="{$orderInfo.status}" data-id="{$orderInfo.id}">重新申请排期</button>
                                            <?php else: ?>
                                                <?php if(($sCate['is_schedule']==1) && ($orderInfo['status']==15)): ?>
                                                    <button class="btn btn-primary btn-sm btn-phase" data-status="{$orderInfo.status}" data-id="{$orderInfo.id}">申请排期</button>
                                                <?php endif;?>
                                            <?php endif;?>
                                            <?php if($orderInfo['status']<30): ?>
                                                <button class="btn btn-info btn-sm btn-update-order" data-status="{$orderInfo.status}" data-id="{$orderInfo.id}">下单</button>
                                            <?php endif;?>
                                        </if>
                                        <div class="text text-black">
                                            <blockquote>
                                                <p>注意事项：</p>
                                                <footer><label class="text text-warning bg-red-active">提前5个工作日询价</label></footer>
                                            </blockquote>
                                        </div>
                                    </div>
                                </div>
                            </div>
                        </div>
                    </if>

                    <if condition="$orderInfo.status egt 25">
                        <div class="box box-info">
                            <div class="box-header with-border">
                                完善订单信息
                            </div>
                            <div class="box-body">
                                <form class="form-horizontal" action="javascript:;" method="post">
                                    <div class="form-group">
                                        <label for="create_time" class="col-sm-2 control-label">下单时间： </label>
                                        <div class="col-sm-10">
                                            <p id="create_time" class="text text-black">{$orderInfo['order_time']}</p>
                                        </div>
                                    </div>
                                    <div class="form-group">
                                        <label for="schedule_remark" class="col-sm-2 control-label">排期备注： </label>
                                        <div class="col-sm-10">
                                            <p id="schedule_remark" class="text text-danger">{$orderInfo.schedule_remark|default='无'}</p>
                                        </div>
                                    </div>
                                    <div class="form-group">
                                        <label for="order_status_desc" class="col-sm-2 control-label">订单状态： </label>
                                        <div class="col-sm-10">
                                            <p id="order_status_desc" class="text text-black">{$orderInfo.status_desc}</p>
                                        </div>
                                    </div>
                                    <div class="form-group">
                                        <label for="admin_name" class="col-sm-2 control-label">部门人员： </label>
                                        <div class="col-sm-10">
                                            <p id="admin_name" class="text text-black">{$orderInfo.admin_name}</p>
                                        </div>
                                    </div>
                                    <div class="form-group">
                                        <label for="order_code" class="col-sm-2 control-label">订单编号： </label>
                                        <div class="col-sm-10">
                                            <p id="order_code" class="text text-black">{$orderInfo.order_code}</p>
                                        </div>
                                    </div>
                                    <div class="form-group">
                                        <label for="o_is_pay" class="col-sm-2 control-label"><span style="color: #f00;">*</span>是否到款： </label>
                                        <div class="col-sm-10">
                                            <select id="o_is_pay" name="o_is_pay" class="form-control">
                                                <option value="0" <if condition="$orderInfo.is_pay eq 0">selected</if>>未到账</option>
                                                <option value="1" <if condition="$orderInfo.is_pay eq 1">selected</if>>已到账</option>
                                            </select>
                                        </div>
                                    </div>
                                    <div class="form-group">
                                        <label for="o_company_name" class="col-sm-2 control-label">终端客户名称：</label>
                                        <div class="col-sm-10">
                                            <input type="text" id="o_company_name" class="form-control" value="{$orderInfo.company_name}">
                                        </div>
                                    </div>
                                    <div class="form-group">
                                        <label for="o_name" class="col-sm-2 control-label">联系人：</label>
                                        <div class="col-sm-10">
                                            <input type="text" id="o_name" class="form-control" value="{$orderInfo.name}">
                                        </div>
                                    </div>
                                    <div class="form-group">
                                        <label for="o_quoted_price" class="col-sm-2 control-label">支付金额： </label>
                                        <div class="col-sm-10">
                                            <input type="text" id="o_quoted_price" class="form-control" value="{$orderInfo.quoted_price}">
                                        </div>
                                    </div>
                                    <div class="form-group">
                                        <label for="o_recharge_price" class="col-sm-2 control-label"><span style="color: #f00;">*</span> 账户充值金额： </label>
                                        <div class="col-sm-10">
                                            <input type="text" class="form-control" id="o_recharge_price" value="{$orderInfo.recharge_price}">
                                        </div>
                                    </div>
                                    <div class="form-group">
                                        <label for="o_pay_interval" class="col-sm-2 control-label"><span style="color: #f00;">*</span>账期： </label>
                                        <div class="col-sm-4 input-group">
                                            <input type="text" class="form-control" id="o_pay_interval" placeholder="例如：1、2、3" value="{$orderInfo.pay_interval}">
                                            <span class="input-group-btn">
                                              <button type="button" class="btn btn-info btn-flat">个月（数字）</button>
                                            </span>
                                        </div>
                                    </div>
                                    <div class="form-group">
                                        <label for="o_agent_name" class="col-sm-2 control-label"><span style="color: #f00;">*</span>公司名(代理商): </label>
                                        <div class="col-sm-10">
                                            <input id="o_agent_name" class="form-control" type="text" value="{$orderInfo.agent_name}">
                                        </div>
                                    </div>
                                    <div class="form-group">
                                        <label for="o_ditch_company" class="col-sm-2 control-label">渠道公司: </label>
                                        <div class="col-sm-10">
                                            <input id="o_ditch_company" class="form-control" type="text" value="{$orderInfo.ditch_company}">
                                        </div>
                                    </div>
                                    <div class="form-group">
                                        <label for="o_mobile" class="col-sm-2 control-label">手机号： </label>
                                        <div class="col-sm-10">
                                            <input id="o_mobile" class="form-control" type="text" value="{$orderInfo.mobile}">
                                        </div>
                                    </div>
                                    <div class="form-group">
                                        <label for="o_product_name" class="col-sm-2 control-label">项目： </label>
                                        <div class="col-sm-10">
                                            <input id="o_product_name" class="form-control" type="text" value="{$orderInfo.product_name}">
                                        </div>
                                    </div>
                                    <div class="form-group">
                                        <label for="o_amount" class="col-sm-2 control-label"><span style="color: #f00;">*</span>销售金额 </label>
                                        <div class="col-sm-10">
                                            <input id="o_amount" class="form-control" type="text" value="{$orderInfo.amount}">
                                        </div>
                                    </div>
                                    <div class="form-group">
                                        <label for="o_rebate" class="col-sm-2 control-label"><span style="color: #f00;">*</span>客户享受返点 </label>
                                        <div class="col-sm-10">
                                            <input id="o_rebate" class="form-control" type="text" value="{$orderInfo.rebate}">
                                        </div>
                                    </div>
                                    <div class="form-group">
                                        <label for="o_other" class="col-sm-2 control-label">其他 </label>
                                        <div class="col-sm-10">
                                            <input name="o_other" id="o_other" class="form-control" value="{$orderInfo.other}">
                                        </div>
                                    </div>
                                    <div class="form-group">
                                        <label for="o_remark" class="col-sm-2 control-label">备注 </label>
                                        <div class="col-sm-10">
                                            <textarea name="o_remark" id="o_remark" class="form-control" rows="5">{$orderInfo.remark}</textarea>
                                        </div>
                                    </div>
                                    <div class="form-group">
                                        <label for="o_is_bill" class="col-sm-2 control-label"><span style="color: #f00;">*</span>发票: </label>
                                        <div class="col-sm-10">
                                            <select id="o_is_bill" name="o_is_bill" class="form-control">
                                                <option value="0" <if condition="$orderInfo.is_bill eq 0">selected</if>>未开</option>
                                                <option value="1" <if condition="$orderInfo.is_bill eq 1">selected</if>>已开</option>
                                            </select>
                                        </div>
                                    </div>
                                    <div class="form-group">
                                        <label for="o_is_filing" class="col-sm-2 control-label"><span style="color: #f00;">*</span>合同: </label>
                                        <div class="col-sm-10">
                                            <select id="o_is_filing" name="o_is_filing" class="form-control">
                                                <option value="0" <if condition="$orderInfo.is_filing eq 0">selected</if>>未归档</option>
                                                <option value="1" <if condition="$orderInfo.is_filing eq 1">selected</if>>已归档</option>
                                            </select>
                                        </div>
                                    </div>
                                    <div class="form-group">
                                        <label class="control-label col-sm-2"></label>
                                        <div class="col-sm-6">
                                            <ul class="list-inline">
                                                <li><button type="button" class="btn btn-sm btn-danger btn-order-completion">终止服务</button></li>
                                                <li><button type="button" class="btn btn-sm btn-success btn-order-save" data-id="{$orderInfo.order_id}" <if condition="$orderInfo.status egt 30">disabled</if> >提交下单</button></li>
                                                <li><button type="reset" class="btn btn-sm btn-info">重置表单</button></li>
                                            </ul>
                                        </div>
                                    </div>
                                </form>
                            </div>
                        </div>
                    </if>
                </div>
            </div>
        </div>
    </section>
</div>
<script src="__PUBLIC__/AdminLTE/plugins/layer/layer.js"></script>
<!-- date-range-picker -->
<script src="https://cdnjs.cloudflare.com/ajax/libs/moment.js/2.11.2/moment.min.js"></script>
<script src="__PUBLIC__/AdminLTE/plugins/daterangepicker/daterangepicker.js"></script>
<script type="application/javascript">
    $(function () {
        //Date range picker
        $('.put-time-d').daterangepicker({
            autoUpdateInput: false,
            applyClass : 'btn-sm btn-success',
            cancelClass : 'btn-sm btn-default',
            opens: 'left',
            locale: {
                applyLabel: '确认',
                cancelLabel: '取消',
                fromLabel : '起始时间',
                toLabel : '结束时间',
                customRangeLabel : '自定义',
                weekLabel: 'W',
                daysOfWeek:['日','一','二','三','四','五','六'],
                monthNames:['一月','二月','三月','四月','五月','六月','七月','八月','九月','十月','十一月','十二月'],
                firstDay : 1
            },
            startDate: new Date(),
            endDate: new Date()
        });
        $('.put-time-d').on('apply.daterangepicker', function(ev, picker) {
            $(this).val(picker.startDate.format('MM/DD/YYYY') + ' - ' + picker.endDate.format('MM/DD/YYYY'));
        });
        $('.put-time-d').on('cancel.daterangepicker', function(ev, picker) {
            $(this).val('');
        });
    });
</script>
<script type="application/javascript">
    var orderStatus = '{$orderInfo.status}';
    var orderId = '{$orderInfo.order_id}';
    function check_order_status(status,oid) {
        if(status == -5){
            layer.confirm('该订单业支已拒绝受理，请点击确定重新走下单流程？', {
                shaw:[0,"#555"],
                btn: ['确定'], //按钮
                closeBtn: false
            }, function(){
                $.post('/admin/order/ajaxResetOrder',{
                    order_id: oid
                },function (_data) {
                    if (_data.Code == 999) {
                        layer.msg("操作成功",{time:1000});
                        window.location.reload(true);
                    } else {
                        ArtDialogHlp.showInfo('提示', _data.Msg);
                        return false;
                    }
                },"json");
            }, function(){
                //todo
            });
        }
    }
    $(function () {
        check_order_status(orderStatus,orderId);
        //贴吧删除
        var $eventSelect = $(".oi_post_bar");
        $eventSelect.on('beforeItemRemove', function(event) {
            var tag = event.item;
            ArtDialogHlp.showConfirm('提示',"确认删除该贴吧吗？",function () {

            },function () {
                var T= (event.currentTarget).id;
                $("#"+T).tagsinput('add',tag);
            });
        });
        //checkbox
        $('input[type="checkbox"].minimal-red, input[type="radio"].minimal-red').iCheck({
            checkboxClass: 'icheckbox_minimal-red',
            radioClass: 'iradio_minimal-red'
        });
        //  投放端口
        $('input[name="put_port"]').on('ifChecked',function (event) {
            var target_name = event.target;
            var id = $(target_name).attr('data-id');
            var strObj = $("#oi_port_"+id).val();
            var strV = event.currentTarget.defaultValue;
            console.info(strObj);
            if(!strObj){
                strObj = new Array();
            }else {
                strObj = strObj.split(',')
            }
            strObj.push(strV);
            strObj.join(',');
            $("#oi_port_"+id).val(strObj);
        }).on('ifUnchecked',function (event) {
            var target_name = event.target;
            var id = $(target_name).attr('data-id');
            var strObj = $("#oi_port_"+id).val();
            var strV = event.currentTarget.defaultValue;
            if(!strObj){
                strObj = new Array();
            }else {
                strObj = strObj.split(',')
            }
            strObj.splice($.inArray(strV, strObj), 1);
            strObj.join(',');
            $("#oi_port_"+id).val(strObj);
        });
        //  投放位置
        $('input[name="put_place"]').on('ifChecked',function (event) {
            var target_name = event.target;
            var id = $(target_name).attr('data-id');
            var strObj = $("#oi_place_"+id).val();
            var strV = event.currentTarget.defaultValue;
            if(!strObj){
                strObj = new Array();
            }else {
                strObj = strObj.split(',')
            }
            strObj.push(strV);
            strObj.join(',');
            $("#oi_place_"+id).val(strObj);
        }).on('ifUnchecked',function (event) {
            var target_name = event.target;
            var id = $(target_name).attr('data-id');
            var strObj = $("#oi_place_"+id).val();
            var strV = event.currentTarget.defaultValue;
            if(!strObj){
                strObj = new Array();
            }else {
                strObj = strObj.split(',')
            }
            var index = $.inArray(strV, strObj);
            if(index>-1){
                strObj.splice($.inArray(strV, strObj), 1);
            }
            strObj.join(',');
            $("#oi_place_"+id).val(strObj);
        });
    });
    //产品选择
    $("#t_id").change(function () {
        var parent_cid = $("#p_id").val();
        var second_cid = $("#s_id").val();
        var three_cid = $("#t_id").val();
        $("#item_id").empty();
        $.post('/admin/item/ajaxGetAllItem',{
                parent_cid: parent_cid,
                second_cid: second_cid,
                three_cid: three_cid
            },function (_data) {
                var str = '<option value="0">请选择</option>';
                if(_data.Code == 999){
                    var all = _data.Data;
                    all.forEach(function (item,index) {
                        str +='<option value="'+item.id+'">'+item.name+'</option>>';
                    })
                }
                $("#item_id").append(str);
            },"JSON");
    });
    //添加
    $(".save-btn").click(function () {
        var order_id = $("#order_id").val();
        var parent_cid = $("#p_id").val();
        var second_cid = $("#s_id").val();
        var three_cid = $("#t_id").val();
        var item_id = $("#item_id").val();

        if(second_cid==0){
            layer.alert('请选择三级分类');
            $('#t_id').focus();
            return false;
        }
        if(item_id==0){
            layer.alert('请选择产品');
            $('#item_id').focus();
            return false;
        }
        $.post('/admin/order/ajaxSaveOrderItem',{
            order_id: order_id,
            parent_cid: parent_cid,
            second_cid: second_cid,
            three_cid: three_cid,
            item_id: item_id
        },function (_data) {
            if(_data.Code==999){
                layer.msg("添加成功",{time:2000});
                window.location.reload(true);
            }else{
                layer.msg(_data.Msg,{time:2000});
                return false;
            }
        },"JSON");
    });
    //信息保存
    $(".btn-save-info").click(function () {
        var id = $(this).attr('data-id');
        var eid = $("#oi_eid_" +id).val()
        var advertiser = $("#oi_advertiser_" +id).val();
        var trade = $("#oi_trade_" +id).val();
        var port = $("#oi_port_" +id).val();
        var place = $("#oi_place_" +id).val();
        var post_bar = $("#oi_post_bar_" +id).val();
        var put_time = $("#oi_put_time_" +id).val();
        var promote_product = $("#oi_promote_product_" +id).val();
        var quoted_type = $("#oi_quoted_type_" +id).val();

        var order_id = $("#order_id").val();
        var item_id = $("#oi_item_id_"+ id).val();

        if((quoted_type!=3) && (put_time=='')){
            layer.msg('请选择投放日期',{time:2000});
            return false;
        }

        var ext = $(this).parent().parent().parent().find(".form-group");
        var s_data = [];
        $.each(ext, function(i, obj){
            var a_obj = $(obj).find(".a_data_"+id);
            var a_obj_title = a_obj.attr('data-title');
            if(a_obj_title && (a_obj_title!='undefined')){
                var a_obj_type = a_obj.attr('data-type');
                var a_obj_values = a_obj.attr('data-values');
                var a_obj_v = $(obj).find(".a_data_v_"+id).val();
                s_data.push({title:a_obj_title,type:a_obj_type,values:a_obj_values,val:a_obj_v});
            }
        });
        $.post('/admin/order/ajaxSaveOrderItem',{
            id: id,
            order_id: order_id,
            item_id: item_id,
            advertiser:advertiser,
            trade: trade,
            port: port,
            eid: eid,
            place: place,
            put_time: put_time,
            post_bar: post_bar,
            promote_product: promote_product,
            quoted_type: quoted_type,
            s_data: s_data
        },function (_data) {
            if(_data.Code==999){
                layer.msg("操作成功",{time:2000});
                window.location.reload(true);
            }else{
                layer.msg(_data.Msg,{time:2000});
                return false;
            }
        },"JSON");
    });
    //删除放弃该项目
    $('.btn-delete').click(function () {
        var id = $(this).attr('data-id');
        var order_id = $("#order_id").val();
        layer.confirm('确认放弃该项目吗?',function () {
            $.post('/admin/order/ajaxDeleteOrderItem',{
                id: id,
                order_id: order_id
            },function (_data) {
                if(_data.Code==999){
                    layer.msg("操作成功",{time:2000});
                    window.location.reload(true);
                }else{
                    layer.msg(_data.Msg,{time:2000});
                    return false;
                }
            },"JSON");
        });
    });
    //申请报价
    $('.btn-quoted').click(function () {
        var order_id = $("#order_id").val();
        layer.confirm('确认申请报价吗?',function () {
            $.post('/admin/customer/ajaxApplyQuoted',{
                order_id: order_id
            },function (_data) {
                if(_data.Code==999){
                    layer.msg("操作成功",{time:2000});
                    window.location.reload(true);
                }else{
                    layer.msg(_data.Msg,{time:2000});
                    return false;
                }
            },"JSON");
        });
    });
    //申请排期
    $('.btn-phase').click(function () {
        var order_id = $("#order_id").val();
        layer.confirm('确认申请排期吗?',function () {
            $.post('/admin/customer/ajaxApplySchedule',{
                order_id: order_id
            },function (_data) {
                if(_data.Code==999){
                    layer.msg("操作成功",{time:2000});
                    window.location.reload(true);
                }else{
                    layer.msg(_data.Msg,{time:2000});
                    return false;
                }
            },"JSON");
        });
    });
    //终止服务
    $('.btn-order-completion').click(function () {
        var order_id = $("#order_id").val();
        layer.confirm('确认终止服务吗?',function () {
            $.post('/admin/customer/ajaxServiceCompletion',{
                order_id: order_id
            },function (_data) {
                if(_data.Code==999){
                    layer.msg("操作成功",{time:2000});
                    window.location.reload(true);
                }else{
                    layer.msg(_data.Msg,{time:2000});
                    return false;
                }
            },"JSON");
        });
    });
    //下单（更新）
    $('.btn-update-order').click(function () {
        var order_id = $("#order_id").val();
        layer.confirm('确认直接下单吗?',function () {
            $.post('/admin/customer/ajaxDirectOrder',{
                order_id: order_id
            },function (_data) {
                if(_data.Code==999){
                    layer.msg("操作成功",{time:2000});
                    window.location.reload(true);
                }else{
                    layer.msg(_data.Msg,{time:2000});
                    return false;
                }
            },"JSON");
        });
    });
    //保存完善订单信息
    $('.btn-order-save').click(function () {
        var order_id = $(this).attr('data-id');
        var o_company_name = $("#o_company_name").val();
        var o_mobile = $("#o_mobile").val();
        var o_name = $("#o_name").val();
        var o_quoted_price = $("#o_quoted_price").val();
        var o_recharge_price = $("#o_recharge_price").val();
        var o_pay_interval = $("#o_pay_interval").val();
        var o_is_pay = $("#o_is_pay").val();
        var o_is_bill = $("#o_is_bill").val();
        var o_is_filing = $("#o_is_filing").val();
        var o_product_name = $("#o_product_name").val();
        var o_agent_name = $("#o_agent_name").val();
        var o_ditch_company = $("#o_ditch_company").val();
        var o_rebate = $("#o_rebate").val();
        var o_remark = $("#o_remark").val();
        var o_amount = $("#o_amount").val();
        var o_other = $("#o_other").val();
        if(o_quoted_price=='' || parseInt(o_quoted_price)<0){
             layer.msg( "请填写支付金额",{time:1000});
              $( "#o_quoted_price").focus(); 
              return false; 
        }
        if(o_recharge_price=='' || parseInt(o_recharge_price)<0){
             layer.msg( "请填写账户充值金额",{time:1000});
              $( "#o_recharge_price").focus(); 
              return false; 
        }
        if(o_pay_interval=='' || isNaN(o_pay_interval)){
            layer.msg("请填写账期",{time:1000});
            $("#o_pay_interval").focus();
            return false;
        }
        if(o_agent_name==''){
            layer.msg("请填写公司代理商",{time:1000});
            $("#o_agent_name").focus();
            return false;
        }
        if(o_amount=='' || parseInt(o_amount)<0){
            layer.msg("请填写销售金额",{time:1000});
            $("#o_amount").focus();
            return false;
        }
        layer.confirm('确认提交下单吗？', {
            btn: ['确认下单','返回修改'] //按钮
        }, function(){
            $.post('/admin/customer/ajaxToSaveOrder',{
                order_id: order_id,
                company_name: o_company_name,
                mobile: o_mobile,
                name: o_name,
                quoted_price: o_quoted_price,
                recharge_price: o_recharge_price,
                pay_interval: o_pay_interval,
                is_pay: o_is_pay,
                is_bill: o_is_bill,
                is_filing: o_is_filing,
                product_name: o_product_name,
                agent_name: o_agent_name,
                ditch_company: o_ditch_company,
                rebate: o_rebate,
                remark: o_remark,
                amount: o_amount,
                other: o_other
            },function (_data) {
                if(_data.Code==999){
                    layer.msg("操作成功",{time:1000});
                    window.location.reload(true);
                }else{
                    layer.msg(_data.Msg,{time:1000});
                    return false;
                }
            },"JSON");
        });
    });
</script>